package com.tsx.dictionary;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.core.env.Environment;

import java.net.InetAddress;

@SpringBootApplication
@Slf4j
public class EnumDictionaryApplication {

    public static void main(String[] args) throws Exception {
        SpringApplication app = new SpringApplicationBuilder(EnumDictionaryApplication.class).build(args);
        Environment env = app.run(args).getEnvironment();

        // 只提取必要的变量
        String protocol = env.getProperty("server.ssl.key-store") != null ? "https" : "http";
        String port = env.getProperty("server.port", "8080");
        String hostAddress = InetAddress.getLocalHost().getHostAddress();
        String appName = env.getProperty("spring.application.name", "application");
        String profiles = String.join(", ", env.getActiveProfiles());

        // 美观的日志输出（无边框，但格式清晰）
        log.info("""
                        
                        🚀 Application '{}' is running!
                        ----------------------------------------
                          Local:   {}://localhost:{}
                          Network: {}://{}:{}
                          Profile(s): {}
                        ----------------------------------------""",
                appName,
                protocol, port,
                protocol, hostAddress, port,
                profiles.isEmpty() ? "default" : profiles
        );
    }

}
